﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IISLogAnalysis.Config;
//for logparser
using LogQuery = MSUtil.LogQueryClassClass;
using NCSALogInputFormat = MSUtil.COMIISNCSAInputContextClassClass;
using LogRecordSet = MSUtil.ILogRecordset; 

namespace IISLogAnalysis.Business
{
    public class LogParser
    {
        public List<string> QueryLog(string logPath)
        {
            

            List<string> listRecord = new List<string>();

            LogQuery oLogQuery = new LogQuery();
            NCSALogInputFormat oInputFormat = new NCSALogInputFormat();
            string query = CommonData.GetQeurySimple(logPath);

            LogRecordSet oRecordSet = oLogQuery.Execute(query, oInputFormat);

            for (; !oRecordSet.atEnd();oRecordSet.moveNext() )
            {
                MSUtil.ILogRecord o = oRecordSet.getRecord();

                string req = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.GetEncoding("gb2312").GetBytes(o.getValue(6).ToString()));

                listRecord.Add(req);
            }

            return listRecord;
        }
    }
}
